package shop.web.controller.front.home;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.area.AreaService;
import shop.services.front.area.bean.Area;
import shop.services.front.indexImg.IndexImgService;
import shop.services.front.indexImg.bean.IndexImg;
import shop.services.front.news.NewsService;
import shop.services.front.news.bean.News;
import shop.core.FrontBaseController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/4/18.
 */
@Controller
@RequestMapping("/")
public class HomeController extends FrontBaseController<News> {
    @Resource
    private NewsService newsService;
    @Resource
    private AreaService areaService;
    @Resource
    private IndexImgService indexImgService;
    @Override
    public Services<News> getService() {
        return newsService;
    }


    /**
     * 页面跳转方法
     *
     * @return
     */
    @RequestMapping({"/", "/index"})
    public String toHome() {
        return "/front/home/home";
    }

    @RequestMapping("/toNewsDetail")
    public String toNewsList() {
        return "/front/home/newsDetail";
    }

    @RequestMapping("/toAreaList")
    public String toAreaList() {
        return "/front/home/areaList";
    }


    /**
     * 查询全部首页轮播图
     *
     * @param indexImg
     * @return
     */
    @RequestMapping(value = "/selectIndexImg", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectIndexImg(IndexImg indexImg) {
        JSONResult jsonResult = new JSONResult();
        List<IndexImg> list = indexImgService.selectList(indexImg);
        jsonResult.setData(list);
        jsonResult.setSuccess(true);
        return jsonResult;
    }

    /**
     * 查询地级市
     * @param area
     * @return
     */
    @RequestMapping(value = "/selectArea", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectArea(Area area) {
        JSONResult jsonResult = new JSONResult();
        List<Area> list = areaService.selectList(area);
        jsonResult.setData(list);
        jsonResult.setSuccess(true);
        return jsonResult;
    }



}